package com.crazyteam.genid.controller;

import com.crazyteam.genid.util.PrimaryUtils;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/manager/genId", consumes = {MediaType.APPLICATION_JSON_UTF8_VALUE, MediaType.APPLICATION_JSON_VALUE},
        produces = {MediaType.APPLICATION_JSON_VALUE}, method = RequestMethod.POST)
public class GenerateIdController {

    @RequestMapping(value = "next")
    public String next(@RequestParam("primaryKey") String primaryKey){
        return PrimaryUtils.genId(primaryKey);
    }

    @RequestMapping(value = "nextWithStep")
    public String nextWithStep(@RequestParam("primaryKey") String primaryKey,
                               @RequestParam("step") Integer step){
        return PrimaryUtils.genId(primaryKey, step);
    }

    @RequestMapping(value = "nextIncrement")
    public String nextIncrement(@RequestParam("primaryKey") String primaryKey){
        return PrimaryUtils.nextIncrement(primaryKey);
    }

    @RequestMapping(value = "nextLenInc")
    public String nextLenInc(@RequestParam("primaryKey") String primaryKey, @RequestParam("length") Integer length){
        return PrimaryUtils.nextIncrement(primaryKey, length-1);
    }

    @RequestMapping(value = "genIdByRule")
    public String genIdByRule(@RequestParam("primaryKey") String primaryKey, @RequestParam("length") Integer length,
                              @RequestParam("timePrefixNum") Integer timePrefixNum,@RequestParam("step") Integer step,@RequestParam("needCheck") Boolean needCheck){
        return PrimaryUtils.genIdByRule(primaryKey, timePrefixNum,length,step,needCheck);
    }

}
